#!/usr/bin/perl
# servers.cgi
# Copyright (C) 2006  Stephane Alnet
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 

#
# For more information: http://carrierclass.net/
#
use strict; use warnings;
use CGI;
use lib '/home/www/content'; use ccncgi;

my $cgi = new CGI();
print $cgi->header();
print <<'EOT';
<html>
<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <title>CarrierClass.net</title>
    <link rel="stylesheet" type="text/css" href="/css/default.css" />
    
    <script type="text/javascript">
    	djConfig = { isDebug: false };
    </script>
    <script type="text/javascript" src="./js/dojo/dojo.js"></script>
    <script type="text/javascript">
      dojo.require("dojo.event.*");
      dojo.require("dojo.io.*");
      dojo.require("dojo.widget.LayoutContainer");
      dojo.require("dojo.widget.TabContainer");
	  dojo.require("dojo.widget.ContentPane");
      dojo.require("dojo.widget.*");      
    </script>
</head>

    <body id="main" onload="">
EOT

print "<table><tr><th>Name</th><th>IP Address</th><th>Memory</th><th>Swap</th><th>Disk</th><th>Others</th></tr>\n";
open(my $fh, '<', '/home/www/data/servers') or die "open(/home/www/data/servers): $!";
while(<$fh>)
{
    chomp;
    my ($name,$ip) = split;

    spool_request("gather-server-information $ip");

    print qq(<tr><th>$name</th><td><a href="server.cgi?ip=$ip">$ip</a></td>);
    print qq(<td><div id="memfree-$ip" dojoType="ProgressBar" width="150" height="16" dataSource="server-memfree.cgi?ip=$ip" pollInterval="120000"></div></td>);
    print qq(<td><div id="swapfree-$ip" dojoType="ProgressBar" width="150" height="16" dataSource="server-swapfree.cgi?ip=$ip" pollInterval="120000"></div></td>);
    print qq(<td><div id="diskfree-$ip" dojoType="ProgressBar" width="150" height="16" dataSource="server-diskfree.cgi?ip=$ip" pollInterval="120000"></div></td>);
    print qq(</tr>\n);
}
print qq(</table></body></html>\n);
exit 0;
